#pragma once

#include <string>
#include <fstream>

namespace util {

class File
{
public:
    enum OpenMode {
        NotOpen = 0x0000,
        ReadOnly = 0x0001,
        WriteOnly = 0x0002,
        ReadWrite = ReadOnly | WriteOnly,
        Append = 0x0004,
        Truncate = 0x0008,
        Text = 0x0010,
    };

    File();
    ~File();
    void setFileName(const std::string &fileName);
    bool open(OpenMode = ReadWrite);
    bool isOpen() const;
    void close();
    void flush();
    bool eof() const;
    bool seek(long long pos);
    long long pos();
    long long fileSize();
    size_t read(char *buf, size_t size);
    size_t write(const char *buf, size_t size);

private:
    std::string m_fileName;
    std::fstream m_fs;
    OpenMode m_mode;
};

}
